#!/usr/bin/python

# TODO
# 1. how to set the transparency of axes ?
# 2. add_subplot ?
# 3.


from pylab import *

fig = figure()
ax1 = fig.add_subplot(211)              # 2 rows, 1 column, first plot 
ax2 = fig.add_subplot(212)              # infact, subplot is a subclass of Axes
# ax2 = fig.add_subplot(212, projection='polar') # add a polar subplot
ax3 = fig.add_axes([0,0,0.4,0.2])
ax4 = fig.add_axes([0.2,0.15,0.4,0.25])



x = arange(0,2*pi,0.1)
y1 = sin(2*pi*x)
y2 = sin(2*pi*x)*exp(-x)

ax1.plot(x,y1,'b')
ax1.set_title("$sin(2\pi{x})$")
ax1.set_ylabel("Volts")
ax2.plot(x,y2,'r')

ax3.plot(x,y2,'g')
ax4.plot(x,y2,'y', linewidth=3)
ax4.set_axis_bgcolor('#99ff99')
# ax4.set_xlabel("$sin(2\pi{x})*exp(-x)")  # this expression not correct 


# turn all the axes grids on
for ax in fig.axes:
    ax.grid(True)

show()


# x = np.linspace(-np.pi, np.pi, 256, endpoint=True)
# y, z = np.sin(x), np.cos(x)

# # plot(x,y)
# # plot(x,z)
# # show()

# # create a new figure of size 8x6 points, using 80 dots per inch
# figure(figsize=(8,6), dpi=80)

# plot(x,y, label="$sin(x)$", color="blue", linewidth=2.0, linestyle="-")
# plot(x,z, label="$cos(x)$", color="red", linewidth=2.0, linestyle="--")

# # set title, label, legend and grid
# title("PyPlot example")
# xlabel("Time(s)")
# ylabel("Volt")
# # legend()
# legend(loc="upper left")
# grid()                          # only grid x ?? or grid y ??

# # set x/y limits/ticks
# # xlim(-4.0, 4.0)
# xlim(x.min()*1.1, x.max()*1.1)
# # xticks(np.linspace(-4,4,9, endpoint=True))
# xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi], ['$-\pi$', '$-\pi/2$', '$0$', '$+\pi/2$', '$+\pi$'])
# # ylim(-1.0, 1.0)
# ylim(y.min()*1.1, y.max()*1.1)
# yticks(np.linspace(-1,1,11,endpoint=True))


# # spines ???
# # ax = gca()
# # ax.spines['right'].set_color('none')
# # ax.spines['top'].set_color('none')
# # ax.xaxis.set_ticks_position('bottom')
# # ax.spines['bottom'].set_position(('data', 0))
# # ax.yaxis.set_ticks_position('left')
# # ax.spines['left'].set_position(('data', 0))

# #annotate some points
# t = 2*np.pi/3
# plot([t,t], [0, np.sin(t)], color='blue', linewidth=2.5, linestyle='--')
# scatter([t,], [np.sin(t),], 50, color='blue')
# annotate(r'$\sin(\frac{2\pi}{3})=\frac{\sqrt{3}}{2}$',
#          xy=(t, np.sin(t)), xycoords='data',
#          xytext=(+10, +30), textcoords='offset points', fontsize=16,
#          arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.5"))

# plot([t,t], [0, np.cos(t)], color='red', linewidth=2.5, linestyle='--')
# scatter([t,], [np.cos(t),], 50, color='red')
# annotate(r'$\cos(\frac{2\pi}{3})=-\frac{1}{2}$',
#          xy=(t, np.cos(t)), xycoords='data',
#          xytext=(-90, -50), textcoords='offset points', fontsize=16,
#          arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))


# # save figure using 72 dots per inch
# savefig("sin.png", dpi=72)


# # show result on screen
# show()



# # import numpy as np
# # import matplotlib.pyplot as plt

# # # x = np.linspace(0, 10, 100)
# # x = np.arange(0, 10, 0.02)
# # y = np.sin(x)
# # z = np.cos(0.5*x)

# # # plt.plot(x, np.sin(x))
# # # plt.show()


# # plt.figure(figsize=(8,4))
# # ####################
# # ## the actual plot
# # # plt.plot(x,y, linewidth=4)
# # plt.plot(x,y,label="$sin(x)$", color="red", linewidth=2)
# # # plt.plot(x,z,"b--", label="$cos(0.5*x)$")
# # plt.plot(x,z,"bo", label="$cos(0.5*x)$")
# # ####################
# # # the ??
# # plt.title("PyPlot example")
# # plt.xlabel("Time(s)")
# # plt.ylabel("Volt")
# # plt.legend()
# # plt.ylim(-1.2, 1.2)
# # # plt.xlim(0, 15)
# # plt.grid()


# # plt.show()



